<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="文件序号" prop="fileXh">
      <el-input v-model="dataForm.fileXh" placeholder="文件序号"></el-input>
    </el-form-item>
    <el-form-item label="文件名称" prop="fileName">
      <el-input v-model="dataForm.fileName" placeholder="文件名称"></el-input>
    </el-form-item>
    <el-form-item label="文件类型" prop="fileType">
      <el-input v-model="dataForm.fileType" placeholder="文件类型"></el-input>
    </el-form-item>
    <el-form-item label="文件备注" prop="fileRemark">
      <el-input v-model="dataForm.fileRemark" placeholder="文件备注"></el-input>
    </el-form-item>
    <el-form-item label="文件路径" prop="fileUrl">
      <el-input v-model="dataForm.fileUrl" placeholder="文件路径"></el-input>
    </el-form-item>
    <el-form-item label="文件磁盘名称" prop="fileRealname">
      <el-input v-model="dataForm.fileRealname" placeholder="文件磁盘名称"></el-input>
    </el-form-item>
    <el-form-item label="创建人id" prop="createId">
      <el-input v-model="dataForm.createId" placeholder="创建人id"></el-input>
    </el-form-item>
    <el-form-item label="创建用户姓名" prop="createName">
      <el-input v-model="dataForm.createName" placeholder="创建用户姓名"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改人id" prop="updateId">
      <el-input v-model="dataForm.updateId" placeholder="修改人id"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="修改用户姓名" prop="updateName">
      <el-input v-model="dataForm.updateName" placeholder="修改用户姓名"></el-input>
    </el-form-item>
    <el-form-item label="版本号" prop="version">
      <el-input v-model="dataForm.version" placeholder="版本号"></el-input>
    </el-form-item>
    <el-form-item label="删除标识 -1：删除 0：正常" prop="gcFlag">
      <el-input v-model="dataForm.gcFlag" placeholder="删除标识 -1：删除 0：正常"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          fileXh: '',
          fileName: '',
          fileType: '',
          fileRemark: '',
          fileUrl: '',
          fileRealname: '',
          createId: '',
          createName: '',
          createTime: '',
          updateId: '',
          updateTime: '',
          updateName: '',
          version: '',
          gcFlag: ''
        },
        dataRule: {
          fileXh: [
            { required: true, message: '文件序号不能为空', trigger: 'blur' }
          ],
          fileName: [
            { required: true, message: '文件名称不能为空', trigger: 'blur' }
          ],
          fileType: [
            { required: true, message: '文件类型不能为空', trigger: 'blur' }
          ],
          fileRemark: [
            { required: true, message: '文件备注不能为空', trigger: 'blur' }
          ],
          fileUrl: [
            { required: true, message: '文件路径不能为空', trigger: 'blur' }
          ],
          fileRealname: [
            { required: true, message: '文件磁盘名称不能为空', trigger: 'blur' }
          ],
          createId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          createName: [
            { required: true, message: '创建用户姓名不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          updateName: [
            { required: true, message: '修改用户姓名不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号不能为空', trigger: 'blur' }
          ],
          gcFlag: [
            { required: true, message: '删除标识 -1：删除 0：正常不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sys/sysfiletable/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.fileXh = data.sysfiletable.fileXh
                this.dataForm.fileName = data.sysfiletable.fileName
                this.dataForm.fileType = data.sysfiletable.fileType
                this.dataForm.fileRemark = data.sysfiletable.fileRemark
                this.dataForm.fileUrl = data.sysfiletable.fileUrl
                this.dataForm.fileRealname = data.sysfiletable.fileRealname
                this.dataForm.createId = data.sysfiletable.createId
                this.dataForm.createName = data.sysfiletable.createName
                this.dataForm.createTime = data.sysfiletable.createTime
                this.dataForm.updateId = data.sysfiletable.updateId
                this.dataForm.updateTime = data.sysfiletable.updateTime
                this.dataForm.updateName = data.sysfiletable.updateName
                this.dataForm.version = data.sysfiletable.version
                this.dataForm.gcFlag = data.sysfiletable.gcFlag
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sys/sysfiletable/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'fileXh': this.dataForm.fileXh,
                'fileName': this.dataForm.fileName,
                'fileType': this.dataForm.fileType,
                'fileRemark': this.dataForm.fileRemark,
                'fileUrl': this.dataForm.fileUrl,
                'fileRealname': this.dataForm.fileRealname,
                'createId': this.dataForm.createId,
                'createName': this.dataForm.createName,
                'createTime': this.dataForm.createTime,
                'updateId': this.dataForm.updateId,
                'updateTime': this.dataForm.updateTime,
                'updateName': this.dataForm.updateName,
                'version': this.dataForm.version,
                'gcFlag': this.dataForm.gcFlag
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
